/*
 *
 * 判断是否可以提交内容
 * */
var html ='';//用于存放编辑页面的内容
var editStatus = false;
/*var pcStatus = false;
var h5Status = false;*/
function judgeSubmit(){
	var title = $('#title').val().replace(/(^\s+)|(\s+$)/g,"");//去除前后空格
	title = Boolean(title);
	if(title && editStatus /*&& pcStatus && h5Status*/){
		return true;
	}else{
		return false;
	}
}

//删除图片
$('.deleteImg').on('click',function(){
	$(this).parent().remove();
})
//上传pc banner图
$('.upPcBanner').on('change',function(){
	pcFile(this.files);
})
//上传h5 banner图
$('.upH5Banner').on('change',function(){
	h5Banner(this.files);
})

var imgDelete = $('#imgDelete').val();

//pc添加图片
function pcFile(files){
	var img = document.createElement("img");
	img.file = files[0];
	img.className = 'pcBannerImg';
	var str = '<div class="pcBanner"><img src="'+imgDelete+'" class="deleteImg" alt="" /></div>';
	$('.pcBannerSee').html(str);
	$('.pcBanner').get(0).insertBefore(img,$('.pcBanner .deleteImg').get(0));
    var reader = new FileReader();
    reader.onload = (function(aImg) {
	      return function(e) {
	        aImg.src = e.target.result;
	      };
	    })(img);
	    reader.readAsDataURL(files[0]);
	   /* pcStatus = true;*/
}
//h5添加图片
function h5Banner(files){
	var img = document.createElement("img");
	img.file = files[0];
	img.className = 'h5BannerImg';
	var str = '<div class="h5Banner"><img src="'+imgDelete+'" class="deleteImg" alt="" /></div>';
	$('.h5BannerSee').html(str);
	$('.h5Banner').get(0).insertBefore(img,$('.h5Banner .deleteImg').get(0));
    var reader = new FileReader();
    reader.onload = (function(aImg) {
	      return function(e) {
	        aImg.src = e.target.result;
	      };
	    })(img);
	    reader.readAsDataURL(files[0]);
	    /*h5Status = true;*/
}

/*
 保存按钮
 * */
$('.submit').on('click',function(){
	/*
	 若内容不为空则提交表单
	 若内容为空则提示用户
	 * */
	var title = $('#title').val().replace(/(^\s+)|(\s+$)/g,"");
	if(judgeSubmit()){
		$('#editContent').val(html);
		$('#postInfo').submit();
	}else{
		showHide();
	}
})

/*
 提示动画
 * */
function showHide(){
	$('#tip').animate({
		"opacity" : "0.5"
	},2000,function(){7
		$("#tip").animate({
			"opacity" : "0"
		},2000);
	})
}
/*完成描述*/
$('.contEnd').on('click',function(){
	var strCont = $('#editorContent').html().replace(/(^\s+)|(\s+$)/g,"");
	if(strCont!=""){
		//可提交 /discover/addDiscoverajax.htm
		html = $('#editorContent').html();
		editStatus = true;
		$('#wrapWrap').hide();
		$('.mainWrap').show();
		//imgFirst.val($('.choosedImg').eq(0).find('img').eq(0).attr('src'));
	}else{
		showHide();
	}
})
